﻿using System;
using System.Collections.Generic;
using System.Text;
using XPTable.Renderers;
using XPTable.Events;
using System.Windows.Forms;
using System.Drawing;
using XPTable.Sorting;
using XPTable.Editors;
using System.ComponentModel;
using XPTable.Models;

namespace HefaSyncTool.Controls
{
    /// <summary>
    /// Summary description for TextColumn.
    /// </summary>
    [DesignTimeVisible(false),
    ToolboxItem(false)]
    public class HyperLinnkColumn : Column
    {
        
        public delegate void ClickEventHandler(int row, int col);

        public event ClickEventHandler Submit;
        public event ClickEventHandler Refresh;
        public event ClickEventHandler Delete;
        public event ClickEventHandler Edit;
        #region Constructor

        /// <summary>
        /// Creates a new TextColumn with default values
        /// </summary>
        public HyperLinnkColumn()
            : base()
        {

        }


        /// <summary>
        /// Creates a new TextColumn with the specified header text
        /// </summary>
        /// <param name="text">The text displayed in the column's header</param>
        public HyperLinnkColumn(string text)
            : base(text)
        {

        }


        #endregion


        #region Methods

        /// <summary>
        /// Gets a string that specifies the name of the Column's default CellRenderer
        /// </summary>
        /// <returns>A string that specifies the name of the Column's default 
        /// CellRenderer</returns>
        public override string GetDefaultRendererName()
        {
            return "HYPER";
        }


        /// <summary>
        /// Gets the Column's default CellRenderer
        /// </summary>
        /// <returns>The Column's default CellRenderer</returns>
        public override ICellRenderer CreateDefaultRenderer()
        {
            return new HyperLinkRenderer(this);
        }


        /// <summary>
        /// Gets a string that specifies the name of the Column's default CellEditor
        /// </summary>
        /// <returns>A string that specifies the name of the Column's default 
        /// CellEditor</returns>
        public override string GetDefaultEditorName()
        {
            return "HYPER";
        }


        /// <summary>
        /// Gets the Column's default CellEditor
        /// </summary>
        /// <returns>The Column's default CellEditor</returns>
        public override ICellEditor CreateDefaultEditor()
        {
            return null;
        }

        #endregion

        public void RaiseEvent(int row, int col, int type)
        {
            if (type == 0)
            {
                if (Submit != null)
                {
                    Submit(row, col);
                }
            }
            if (type == 1)
            {
                if (Refresh != null)
                {
                    Refresh(row, col);
                }
            }
            if (type == 2)
            {
                if (Delete != null)
                {
                    Delete(row, col);
                }
            }
            if (type == 3)
            {
                if (Edit != null)
                {
                    Edit(row, col);
                }
            }
        }

        #region Properties

        /// <summary>
        /// Gets the Type of the Comparer used to compare the Column's Cells when 
        /// the Column is sorting
        /// </summary>
        public override Type DefaultComparerType
        {
            get
            {
                return typeof(TextComparer);
            }
        }

        #endregion
    }
}
